﻿using Autofac;
using Autofac.Integration.Mvc;
using Remember.Persistence;
using Remember.Persistence.DapperNet;
using Remember.Web.Service;
using System.Reflection;
using System.Web.Mvc;

namespace Remember.Web
{
    /// <summary>
    /// Autofac 注册
    /// </summary>
    public class AutoIoc
    {
        /// <summary>
        /// Autofac 注册
        /// </summary>
        public static void IocRegister()
        {
            var builder = new ContainerBuilder();

            // 注入LoginFormBinder
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType<Authentication>().As<IAuthentication>();
            builder.RegisterModule<AutofacWebTypesModule>();
            builder.RegisterModule<DbModule>();

            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
    }
}